﻿using System;
using System.Threading.Tasks;
using Iot.Shared.Enums;
using Iot.Shared.Model;
using Iot.Shared.Path;

namespace Iot.Shared.EventBusSend;

/// <summary>
///     数据总线帮助类
/// </summary>
public static class EventBusHelp
{
    /// <summary>
    ///     枚举类数据发送
    /// </summary>
    /// <param name="send"></param>
    /// <param name="path"></param>
    /// <param name="data"></param>
    /// <param name="timeStamp"></param>
    /// <returns></returns>
    public static ValueTask SendEnumAsync(this IEventBusSend send, DevicePath path, Enum? data,
        DateTimeOffset? timeStamp = null)
    {
        return send.SendAsync(new EnumBusModel(path, data), timeStamp);
    }

    /// <summary>
    ///     双精度浮点数模拟量数据发送
    /// </summary>
    /// <param name="send"></param>
    /// <param name="path"></param>
    /// <param name="data"></param>
    /// <param name="timeStamp"></param>
    /// <returns></returns>
    public static ValueTask SendFloatAsync(this IEventBusSend send, DevicePath path, double? data,
        DateTimeOffset? timeStamp = null)
    {
        return send.SendAsync(new FloatBusModel(path, data), timeStamp);
    }

    /// <summary>
    ///     单精度浮点数模拟量数据发送
    /// </summary>
    /// <param name="send"></param>
    /// <param name="path"></param>
    /// <param name="data"></param>
    /// <param name="timeStamp"></param>
    /// <returns></returns>
    public static ValueTask SendIntegerAsync(this IEventBusSend send, DevicePath path, long? data,
        DateTimeOffset? timeStamp = null)
    {
        return send.SendAsync(new IntegerBusModel(path, data), timeStamp);
    }

    /// <summary>
    ///     开关量数据发送
    /// </summary>
    /// <param name="send"></param>
    /// <param name="path"></param>
    /// <param name="data"></param>
    /// <param name="timeStamp"></param>
    /// <param name="additional"></param>
    /// <returns></returns>
    public static ValueTask SendSwitchingAsync(this IEventBusSend send, DevicePath path, Switching? data,
        DateTimeOffset? timeStamp = null, string? additional = null)
    {
        return send.SendAsync(new SwitchBusModel(path, data, additional), timeStamp);
    }

    /// <summary>
    ///     开关量数据发送
    /// </summary>
    /// <param name="send"></param>
    /// <param name="path"></param>
    /// <param name="data"></param>
    /// <param name="additional"></param>
    /// <returns></returns>
    public static ValueTask SendSwitchingAsync(this IEventBusSend send, DevicePath path, Switching? data,
        string additional)
    {
        return send.SendAsync(new SwitchBusModel(path, data, additional));
    }
}